//
//  YTYunTaiCell.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/20.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTYunTaiCell.h"
#import "YTSetUtils.h"
@interface YTYunTaiCell ()
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *subLabel;
@property(nonatomic, strong)YTSetUtils *utilsView;
@property(nonatomic, strong)UISwitch *switchBtn;
@property(nonatomic, strong)YTSetUtils *utilsView2;
@end

@implementation YTYunTaiCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self p_addSubViews];
        [self p_makeConstraints];
    }
    return self;
}
-(void)p_addSubViews
{
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:17];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_titleLabel];
    
    _subLabel = [[UILabel alloc] init];
    _subLabel.textColor = [UIColor whiteColor];
    _subLabel.font = [UIFont systemFontOfSize:15];
    _subLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_subLabel];
    
    _switchBtn = [[UISwitch alloc] init];
    [self addSubview:_switchBtn];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = YTColorAlpha(180, 180, 180, 0.3);
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}
-(void)p_makeConstraints
{
    [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(10);
        make.top.bottom.trailing.equalTo(self);
    }];
    [_subLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-30);
        make.leading.top.bottom.equalTo(self);
    }];
    [_switchBtn mas_remakeConstraints:^(MASConstraintMaker *make)
     {
         make.trailing.equalTo(self).offset(-10);
         make.centerY.equalTo(self);
         make.width.mas_equalTo(51);
         make.height.mas_equalTo(31);
     }];
}
-(void)configObject:(NSArray *)arr
{
    [_utilsView removeFromSuperview];
    _utilsView = nil;
    _utilsView = [[YTSetUtils alloc] init];
    [self addSubview:_utilsView];
    _titleLabel.text = arr[_indexPath.row];
    NSArray *sources, *sources2 = nil;
    if (_indexPath.section == 0)
    {
        _utilsView2.hidden = YES;
        switch (_indexPath.row)
        {
            case 0:
                sources = @[Language(@"慢"), Language(@"中"), Language(@"快"), Language(@"自定义1"), Language(@"自定义2")];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                _subLabel.hidden = YES;
                _switchBtn.hidden = YES;
                _titleLabel.hidden = YES;
                break;
            case 1:
                _titleLabel.hidden = NO;
                _utilsView.hidden = YES;
                _subLabel.hidden = YES;
                _switchBtn.hidden = NO;
                break;
            default:
                break;
        }
    }else if (_indexPath.section == 1)
    {
        _utilsView2.hidden = YES;
        _titleLabel.hidden = NO;
        _utilsView.hidden = YES;
        _subLabel.hidden = YES;
        _switchBtn.hidden = NO;
        switch (_indexPath.row)
        {
            case 0:
                break;
            case 1:
                break;
            default:
                break;
        }
    }else if (_indexPath.section == 2)
    {
        [_utilsView2 removeFromSuperview];
        _utilsView2 = nil;
        _utilsView2 = [[YTSetUtils alloc] init];
        [self addSubview:_utilsView2];
        _subLabel.hidden = YES;
        _switchBtn.hidden = YES;
        _titleLabel.hidden = NO;
        switch (_indexPath.row)
        {
            case 0:
                sources = @[Language(@"0")];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                sources2 = @[Language(@"0")];
                [_utilsView2 showWithTexts:sources2 block:^(NSInteger tag, UIButton *sender) {
                }];
                break;
            case 1:
                sources = @[Language(@"0")];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                sources2 = @[Language(@"0")];
                [_utilsView2 showWithTexts:sources2 block:^(NSInteger tag, UIButton *sender) {
                }];
                break;
            default:
                break;
        }
    }else if (_indexPath.section == 3)
    {
        _utilsView2.hidden = YES;
        _subLabel.hidden = YES;
        _switchBtn.hidden = YES;
        _titleLabel.hidden = NO;
        switch (_indexPath.row)
        {
            case 0:
                sources = @[Language(@"开始校准")];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                break;
            case 1:
                sources = @[Language(@"开始校准")];
                [_utilsView showWithTexts:sources block:^(NSInteger tag, UIButton *sender) {
                }];
                break;
            default:
                break;
        }
    }
    if (_indexPath.section == 0 && _indexPath.row == 0)
    {
        [_utilsView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).offset(20);
            make.centerY.equalTo(self);
            make.height.mas_equalTo(50);
            make.width.mas_equalTo(70*sources.count);
        }];
    }else
    {
        [_utilsView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self).offset(-10);
            make.centerY.equalTo(self);
            make.height.mas_equalTo(50);
            make.width.mas_equalTo(70*sources.count);
        }];
    }
    [_utilsView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(_utilsView.mas_leading).offset(-22);
        make.centerY.equalTo(self);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(70*sources.count);
    }];
}
@end
